import {
  isSameDay,
  isSameWeek,
  isSameMonth,
  isSameQuarter,
  isSameYear,
  startOfDay,
  endOfDay,
  startOfWeek,
  endOfWeek,
  startOfMonth,
  endOfMonth,
  startOfQuarter,
  endOfQuarter,
  startOfYear,
  endOfYear,
  addDays,
  addMonths,
  addQuarters,
  addYears,
  setDate,
  getDate,
  setWeek,
  getWeek,
  setMonth,
  getMonth,
  setQuarter,
  getQuarter,
  setYear,
  getYear,
} from 'date-fns';
import { IGenerateDateConfig, IPickerType } from '../types';

export const dateConfig: Record<IPickerType, IGenerateDateConfig> = {
  date: {
    set: setDate,
    get: getDate,
    offsetDate: addDays,
    isSame: isSameDay,
    startDate: startOfDay,
    endDate: endOfDay,
  },
  week: {
    set: setWeek,
    get: getWeek,
    offsetDate: addDays,
    isSame: isSameWeek,
    startDate: startOfWeek,
    endDate: endOfWeek,
  },
  month: {
    set: setMonth,
    get: getMonth,
    offsetDate: addMonths,
    isSame: (dateLeft, dateRight) =>
      isSameYear(dateLeft, dateRight) && isSameMonth(dateLeft, dateRight),
    startDate: startOfMonth,
    endDate: endOfMonth,
  },
  quarter: {
    set: setQuarter,
    get: getQuarter,
    offsetDate: addQuarters,
    isSame: (dateLeft, dateRight) =>
      isSameYear(dateLeft, dateRight) && isSameQuarter(dateLeft, dateRight),
    startDate: startOfQuarter,
    endDate: endOfQuarter,
  },
  year: {
    set: setYear,
    get: getYear,
    offsetDate: addYears,
    isSame: isSameYear,
    startDate: startOfYear,
    endDate: endOfYear,
  },
};
